# !-*-coding:utf8-*-
from gobang import Gobang, WHITE, BLACK
from gobangAI import GobangAI
import inter

import pygame
from pygame.locals import *
from sys import exit

if __name__ == '__main__':
    board_size = 15
    gobang = Gobang(board_size)

    ai = GobangAI(gobang)

    pygame.init()
    screen = pygame.display.set_mode(inter.get_screen_size(board_size), 0, 32)
    pygame.display.set_caption("GOBANG")

    inter.clear_screen(screen)

    ONE_HUMAN = 1
    ZERO_HUMAN = 0

    ONE_HUMAN = BLACK
    NO_HUMAN = None

    mode = ONE_HUMAN

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            if event.type == MOUSEBUTTONDOWN:
                if mode == ONE_HUMAN:
                    pos = inter.to_grid_pos(event.pos, gobang)
                    if pos != None: gobang.step(WHITE, pos)
        inter.draw_board(screen, gobang)
        pygame.display.update()
        ai.guide(mode)